package org.http.response;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.http.Headers;

import java.time.LocalDateTime;

/**
 * @author andy
 */

@Setter
@Getter
public class ResponseHeaders  extends Headers {

    public ResponseHeaders(int code){
        this.code = code;
        this.phrase = StatusCodeEnum.queryPhrase(code);
    }

    private int code;

    private String phrase;

    private String contentType;

    private int contentLength;

    private String server;

    public String toHeaderString() {
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("%s %d %s\r\n", getVersion(), code, phrase));
        sb.append(String.format("ContentType: %s\r\n", contentType));
        sb.append(String.format("ContentLength: %d\r\n", contentLength));
        sb.append(String.format("Server: %s\r\n",  "TinyServer"));
        sb.append(String.format("Date: %s\r\n", LocalDateTime.now()));
        sb.append(String.format("Connection: %s\r\n", "keep-alive"));
        sb.append("\r\n");
        return sb.toString();
    }

}
